package com.example.demo.service.impl;

import com.example.demo.controller.demo;
import com.example.demo.dao.UserDao;
import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import com.example.demo.utils.MD5Utils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserDao userDao;



    @Override
    public User userLogin(String username, String password) {

        User byNameAndPwd = userDao.findByNameAndPwd(username,MD5Utils.MD5Code(password));
        if (byNameAndPwd!=null){

        }
        return byNameAndPwd;


    }

    @Override
    public int add(User user) {
        try {

            User user1=new User(user.getUsername(),MD5Utils.MD5Code(user.getPassword()));

            userDao.add(user1);
            return 0;
        }catch (Exception e){
            return 1;
        }



    }

    @Override
    public int update(User user) {
        try{

            User user1=new User(user.getUsername(),MD5Utils.MD5Code(user.getPassword()));

            userDao.update(user1);
            return 0;
        }catch (Exception e){
            return 1;
        }
    }
    @Override
    public int del(User user){
        try {

            userDao.del(user);
            return 0;
        }catch (Exception e){
            return 1;
        }
    }



}